<template>
  <div id="app">
    <el-col :span="3" class="left">
      <div class="logo">
        <img :src="logoSrc" />
      </div>
      <p>数据中心</p>

      <el-menu
        :default-active="activeIndex"
        router
        :unique-opened="true"
        class="el-menu-vertical-demo left"
        @open="handleOpen"
        @close="handleClose"
        background-color="#000"
        text-color="#fff"
        active-text-color="#2768c2"
      >
        <el-menu-item index="/Home" route="/Home">
          <i class="el-icon-menu"></i>
          <span slot="title">数据中心总览</span>
        </el-menu-item>
        <el-submenu index="2">
          <template slot="title">
            <i class="el-icon-s-order"></i>
            <span>学生基本数据</span>
          </template>
          <el-menu-item index="/studentData" route="/studentData"
            >学生数据</el-menu-item
          >
          <!-- <el-menu-item index="2-2" route="/UploadTable">上传溯源表</el-menu-item> -->
          <!-- <el-menu-item index="/StuDataQuery" route="/StuDataQuery"
            >数据查询</el-menu-item
          > -->
          <el-menu-item
            index="/GraInfoManage"
            route="/GraInfoManage"
            v-show="school_code !== '14544'"
            >毕业生信息管理</el-menu-item
          >
          <el-submenu index="2-5">
            <template slot="title">学生异差提醒</template>
            <el-menu-item index="/Dept" route="/Dept">教务处</el-menu-item>
            <el-menu-item index="/StuAffairs" route="/StuAffairs"
              >学生处</el-menu-item
            >
            <el-menu-item index="/FinanceOffice" route="/FinanceOffice"
              >财务处</el-menu-item
            >
            <el-menu-item index="/DataCenter" route="/DataCenter"
              >数据中心</el-menu-item
            >
          </el-submenu>
          <!-- <el-menu-item index="/SyncRecord" route="/SyncRecord"
            >同步记录</el-menu-item
          > -->
        </el-submenu>

        <el-submenu index="3">
          <template slot="title">
            <i class="el-icon-s-custom"></i>
            <span>教职工基本数据</span>
          </template>
          <el-menu-item index="/StaffBasicInfo" route="/StaffBasicInfo"
            >教职工基本信息</el-menu-item
          >
          <!-- <el-menu-item index="/StuDataQuery" route="/StuDataQuery"
            >数据查询</el-menu-item
          > -->
          <!-- <el-menu-item index="3-3" route="/StaffSyncRecord">同步记录</el-menu-item> -->
        </el-submenu>

        <!-- 南影 收费系统数据 放在 教职工基本数据 下面 -->
        <el-submenu index="7" v-show="school_code === '14544'">
          <template slot="title">
            <i class="el-icon-money"></i>
            <span>收费系统数据</span>
          </template>
          <el-menu-item index="/StuFeeInfo" route="/StuFeeInfo"
            >学生收费信息</el-menu-item
          >
          <!-- <el-menu-item index="/StuDataQuery" route="/StuDataQuery"
            >数据查询</el-menu-item
          > -->
          <!-- <el-menu-item index="7-3" route="/BillSyncRecord">同步记录</el-menu-item> -->
        </el-submenu>
        <el-submenu index="4">
          <template slot="title">
            <i class="el-icon-setting"></i>
            <span v-show="school_code !== '14544'">教务系统数据</span>
            <span v-show="school_code === '14544'">教务数据</span>
          </template>
          <el-menu-item index="/ResultsData" route="/ResultsData"
            >成绩数据</el-menu-item
          >
          <el-menu-item index="/TeachingTaskData" route="/TeachingTaskData"
            >教学任务数据</el-menu-item
          >
          <!-- <el-menu-item index="/StuDataQuery" route="/StuDataQuery"
            >数据查询</el-menu-item
          > -->
          <!-- <el-menu-item index="4-4" route="/EduSyncRecord">同步记录</el-menu-item> -->
        </el-submenu>
        <el-submenu index="5">
          <template slot="title">
            <i class="el-icon-reading"></i>
            <span>图书系统数据</span>
          </template>
          <el-menu-item index="/BookInfo" route="/BookInfo"
            >图书信息</el-menu-item
          >
          <el-menu-item index="/LibraryLendingdata" route="/LibraryLendingdata"
            >图书借阅数据</el-menu-item
          >
          <!-- <el-menu-item index="/StuDataQuery" route="/StuDataQuery"
            >数据查询</el-menu-item
          > -->
          <!-- <el-menu-item index="5-4" route="/LibSyncRecord">同步记录</el-menu-item> -->
        </el-submenu>
        <el-submenu index="6" v-show="school_code !== '14544'">
          <template slot="title">
            <i class="el-icon-present"></i>
            <span>消费数据</span>
          </template>
          <!-- <el-menu-item index="6-1" route="/YXTConsumData">院校通消费数据</el-menu-item> -->
          <!-- <el-menu-item index="/StuDataQuery" route="/StuDataQuery"
            >数据查询</el-menu-item
          > -->
          <!-- <el-menu-item index="6-3" route="/YXTSyncRecord">同步记录</el-menu-item> -->
        </el-submenu>
        <el-submenu index="7" v-show="school_code !== '14544'">
          <template slot="title">
            <i class="el-icon-money"></i>
            <span>收费系统数据</span>
          </template>
          <el-menu-item index="/StuFeeInfo" route="/StuFeeInfo"
            >学生收费信息</el-menu-item
          >
          <!-- <el-menu-item index="/StuDataQuery" route="/StuDataQuery"
            >数据查询</el-menu-item
          > -->
        </el-submenu>
      </el-menu>
    </el-col>
    <el-col :span="21" class="right">
      <div class="rightHead">
        <i class="el-icon-bell"></i>
        <div
          class="userInfo userImage"
          @mouseenter="showFn"
          @mouseleave="hideFn"
        >
          <img class="img" src="../assets/homeImg/avatar.png" />

          <div id="userInfoBox" v-show="showLogOut" style="z-index: 999999">
            <div>
              <span @click="logOutFn">
                <i
                  class="el-icon-switch-button"
                  style="color: #f00; font-weight: bolder"
                ></i>
                退出登录</span
              >
            </div>
          </div>
          <!-- <div>
          <el-dropdown>
            <span class="el-dropdown-link">
              <img class="img" src="../assets/homeImg/avatar.png">
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div> -->
          <span>{{ uname }}</span>
        </div>
      </div>
      <router-view />
    </el-col>
  </div>
</template>

<script>
export default {
  name: "Common",
  data() {
    return {
      uname: "",
      showLogOut: false,
      logoSrc: "",
      school_code: "",
      activeIndex: "/Home",
    };
  },
  async mounted() {
    this.activeIndex = this.$route.path;
    await this.getvalue("code");
    await this.setLoginLog();
    await this.getDjxtData();
    var url = window.location.href; //获取当前页面的url
    if (url.indexOf("?") != -1) {
      //判断是否存在参数
      url = url.replace(/(\?|#)[^'"]*/, ""); //去除参数
      window.history.pushState({}, 0, url);
      this.$router.push("Home");
    }
  },
  methods: {
    getDjxtData() {
      this.$get("system/menuLogo/logos").then((r) => {
        let data = null;
        let that = this;
        if (r.data.data.length) {
          data = r.data.data.filter((v) => {
            return v.schoolCode == that.school_code;
          });
          console.log(data, "r.data");
          sessionStorage.setItem("showTotalNum", JSON.stringify(data[0]));

          let logoSrc = data[0].themeLogo
            ? data[0].themeLogo
            : data[0].bottomLogo;
          this.logoSrc = logoSrc;
        }
      });
    },
    showFn() {
      this.showLogOut = true;
    },
    hideFn() {
      this.showLogOut = false;
    },
    logOutFn() {
      // localStorage.removeItem('ACCESS_TOKEN');
      // localStorage.removeItem('USER_ROUTER');
      // localStorage.removeItem('userType');
      // localStorage.removeItem('USER');
      // localStorage.removeItem('userInfo');
      // sessionStorage.removeItem('schoolInfo');
      window.opener = null;
      window.open("", "_self");
      window.close();
      // window.open('https://sso.wq.com/campuskey/logout?reLoginUrl=login&host='+ url +'&color=' + color + '&img1=' + loginBackgroundImage + '&img2=' + loginBackgroundLogo, '_self');
    },
    async setLoginLog() {
      await this.$get("system/user/success").then((res) => {
        sessionStorage.setItem("school", JSON.stringify(res.data));
        this.uname = res.data.userInfo.description;
        this.school_code = res.data.school_code;
      });
    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    getvalue(name) {
      let str = "";
      let isOnline = window.location.port;
      if (isOnline != "8116") {
        // 本地
        str = window.location.search; //本地
      } else {
        // 线上
        str = window.location.search.substr(
          0,
          window.location.search.length - 5
        ); //线上
      }

      if (str.indexOf(name) != -1) {
        var pos_start = str.indexOf(name) + name.length + 1;
        var pos_end = str.indexOf("&", pos_start);
        if (pos_end == -1) {
          // 更新访问令牌
          localStorage.setItem(
            "ACCESS_TOKEN",
            JSON.stringify(str.substring(pos_start))
          );
        }
      }
    },
  },
};
</script>

<style>
body {
  overflow-y: hidden;
}
.left,
.right {
  height: 100vh;
}

.left {
  text-align: left;
}

.left p {
  text-align: center;
}

.right {
  overflow-y: scroll;
}
.rightHead {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  background: #f4f4f6;
  /* padding: 20px 0; */
  background: #fff;
}

.el-icon-bell {
  font-size: 26px;
}

.userInfo {
  display: flex;
  align-items: center;
  margin-right: 100px;
}

.userImage {
  position: relative;
  height: 80px;
  cursor: pointer;
}
#userInfoBox {
  position: absolute;
  background: #ffffff;
  color: #000000;
  font-size: 12px;
  width: 105px;
  line-height: 35px;
  box-shadow: 0px 0px 6px rgba(0, 0, 0, 0.2);
  opacity: 1;
  border-radius: 6px;
  text-align: center;
  border: 1px solid #cccccc;
  top: 66px;
  left: 18px;
}
#userInfoBox div {
  width: 100%;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  border-radius: 6px;
}
#userInfoBox div span:hover {
  border-radius: 6px;
  background-color: rgb(25, 167, 215);
  color: #ccc;
}

.img {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  margin: 0 14px;
}

.left {
  background: #000;
  color: #fff;
}

.left p {
  font-size: 22px;
  padding: 20px 0;
}

.logo {
  min-width: 146px;
  /* width: 180px; */
  height: 30px;
  padding-top: 20px;
  margin: 10px auto;
  /* background: url('../assets/homeImg/logo.png') no-repeat; */
  /* background-size: contain; */
}

.logo img {
  width: 100%;
}

.el-submenu .el-menu-item {
  /* padding: 0 5px!important; */
  min-width: 30px !important;
}

/* .el-menu-item{
  padding-left:16px!important;
} */
</style>
